package com.codec;

import com.alibaba.fastjson.JSON;
import com.entity.MsgData;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.List;

/**
 * @program: mpf-eventbridge
 * @description:
 * @author: zt22328 赵儒定
 * @create: 2022-11-30 09:44
 **/
public class AppConfigEncoder extends MessageToMessageEncoder<MsgData> {

    @Override
    protected void encode(ChannelHandlerContext ctx, MsgData data, List<Object> out) throws Exception {
        if (data == null){
            return;
        }
        out.add(ByteBufUtil.encodeString(ctx.alloc(), CharBuffer.wrap(JSON.toJSONString(data)), Charset.defaultCharset()));
    }
}
